#include<iostream>
#include<fstream>

using std::cout;
using std::ifstream;       // 读文件
using std::ofstream;      // 写文件

int main(){
    ofstream ofile;
    ofile.open("text.txt");
    if(!ofile.is_open()){               // 
        std::cerr<<"cannot open the file";
    }

    ofile << "hello world\nmimi";        // write some message in text.txt
    ofile.close();

    ifstream ifile;
    ifile.open("text.txt");
    if(!ifile){
        std::cerr<<"cannot open the file";
    }
    char buf[1024] = {0};
    while (ifile >> buf)                    // 遇到空格或换行终止
    {
        cout<<buf<<"\n";
    }
    
    ifile.close();
    return 0;
}